/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef ADCSensorTest_H_
#define ADCSensorTest_H_
#include "TestAssert.h"
#include "TestCase.h"
#include "Sensors/ADCSensor.h"
#include "CallbackServers/Callback.h"

using ADCs::ADCHardware;

class ADCSensorTest : public TestCase<ADCSensorTest>
{


public:

	ADCSensorTest(const prog_mem * testMethodName_P, TestCase<ADCSensorTest>::TestMethod testMethod) :
		TestCase<ADCSensorTest>(testMethodName_P, testMethod)
	{
	//		Callback();
		adcHardware = ADCHardware::getInstance();
		adcHardware->setVoltageReference(ADCs::VoltageReferences::AREF);
		adcHardware->setPrescaler(ADCs::Prescalers::DIV_8);
		adcHardware->setChannelMode(ADCs::ChannelModes::ADC0);
		adcHardware->rightAdjust();

		adcSensor0V = new ADCSensor(ADCHardware::getInstance(), ADCs::ChannelModes::ADC0);
		adcSensor3_33V = new ADCSensor(ADCHardware::getInstance(), ADCs::ChannelModes::ADC1);

	}
	~ADCSensorTest()
	{
		delete adcSensor0V;
		delete adcSensor3_33V;
	}

	void setUp()
	{
		adcHardware->enableADC();
		enableInterrupts();

	}

	void tearDown()
	{
		adcHardware->disableADC();
		disableInterrupts();
	}

	bool testRead()
	{

		//Instructions : Put 5V in AREF, 0V in ADC0 and 3.33V in ADC1

		bool result = AVRUNIT_ASSERT_IN_RANGE_LONG(adcSensor3_33V->read().serialize().buffer, 666, 100);

		result = AVRUNIT_ASSERT_IN_RANGE_LONG(adcSensor0V->read().serialize().buffer, 0, 10);

		return result;

	}

protected :
	ADCSensor * adcSensor3_33V;
	ADCSensor * adcSensor0V;
	ADCHardware * adcHardware;

};

#endif /* ADCSensorTest_H_ */
